package com.example.kingdee.kingdeeBridge;

import com.example.kingdee.exception.ProcedureException;
import com.example.kingdee.kingdeeBridge.dto.BillWriteInDto;
import com.example.kingdee.kingdeeBridge.dto.PushDto;
import com.example.kingdee.sqlTool.sqltoolEnum.FormIdEnum;
import org.springframework.stereotype.Service;

@Service
public class PushDownFactory {

    public PushDto createPushDto(BillWriteInDto billWriteInDto){
        switch (billWriteInDto.getBillType()){
            case "采购收料" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.purchaseOrder);
                pushDto.setTargetFormId(FormIdEnum.purReceiveBill);
                return pushDto;
            }
            case "采购入库" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.purReceiveBill);
                pushDto.setTargetFormId(FormIdEnum.stkInStock);
                return pushDto;
            }
            case "来料检验" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.purReceiveBill);
                pushDto.setTargetFormId(FormIdEnum.qmInspect);
                //填充目标组织id
                pushDto.setTargetOrgId(billWriteInDto.getReserved1());
                return pushDto;
            }
            case "生产领料" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.prdPpBom);
                pushDto.setTargetFormId(FormIdEnum.prdPickMtrl);
                pushDto.setEnableDefaultRule(false);
                pushDto.setRuleId("PRD_PPBOM2PICKMTRL_NORMAL");
                return pushDto;
            }
            case "生产调拨" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.prdPpBom);
                pushDto.setTargetFormId(FormIdEnum.sTKTransferDirect);
                return pushDto;
            }
            case "生产汇报" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.proMo);
                pushDto.setTargetFormId(FormIdEnum.proMoRpt);
                return pushDto;
            }
            case "汇报入库" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.proMoRpt);
                pushDto.setTargetFormId(FormIdEnum.proInStock);
                return pushDto;
            }
            case "生产入库" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.proMo);
                pushDto.setTargetFormId(FormIdEnum.proInStock);
                return pushDto;
            }
            case "发货出库" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.deliveryRelease);
                pushDto.setTargetFormId(FormIdEnum.salOutStock);
                return pushDto;
            }
            case "销售出库" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.salSaleOrder);
                pushDto.setTargetFormId(FormIdEnum.salOutStock);
                return pushDto;
            }
            case "生产补料" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.prdPpBom);
                pushDto.setTargetFormId(FormIdEnum.feedMtrl);
                pushDto.setEnableDefaultRule(false);
                pushDto.setRuleId("PRD_PPBOM2FEEDMTRL");
                return pushDto;
            }
            case "生产退料" : {
                PushDto pushDto = new PushDto();
                pushDto.setSrcFormId(FormIdEnum.prdPpBom);
                pushDto.setTargetFormId(FormIdEnum.returnMtrl);
                pushDto.setEnableDefaultRule(false);
                pushDto.setRuleId("PRD_PPBOM2RETURNMTRL");
                //填充目标组织id
                pushDto.setTargetOrgId(billWriteInDto.getReserved1());
                return pushDto;
            }

            default: throw new ProcedureException("请传入正确的单据类型");
        }
    }
}
